package ch04.game;

/**
 * @author chenmin
 * @desc TODO
 * @date 2025/9/3
 */


import java.util.Objects;

/**
 * 抽象角色类：封装英雄/怪兽的共性属性与行为，定义攻击抽象方法
 */
public abstract class Role {

    private String name;
    private int level;
    private int blood;
    private String kind;
    private int basePower;
    private int baseDefence;


    protected static final int CRIT_THRESHOLD = 7;
    protected static final int CRIT_MULTIPLE = 2;
    protected static final int MIN_DAMAGE = 1;


    public Role(String name, int level, int blood, String kind, int basePower, int baseDefence) {
        this.name = Objects.requireNonNull(name, "角色名称不能为null");
        this.level = Math.max(1, level);
        this.blood = Math.max(1, blood);
        this.kind = Objects.requireNonNull(kind, "种族不能为null");
        this.basePower = Math.max(0, basePower);
        this.baseDefence = Math.max(0, baseDefence);
    }


    public abstract void attack(Role target);


    public boolean isDead() {
        return this.blood <= 0;
    }


    public int getTotalPower() {
        return this.basePower;
    }


    public int getTotalDefence() {
        return this.baseDefence;
    }


    public void showBaseInfo() {
        System.out.printf("【%s】- 种族：%s | 等级：%d | 血量：%d | 总攻击力：%d | 总防御力：%d%n",
                name, kind, level, blood, getTotalPower(), getTotalDefence());
    }


    public String getName() {
        return name;
    }

    public int getBlood() {
        return Math.max(0, blood);
    }

    public void setBlood(int blood) {
        this.blood = Math.max(0, blood);
    }

    protected int getBasePower() {
        return basePower;
    }

    protected int getBaseDefence() {
        return baseDefence;
    }
}
